Conditions | 1 |
Total Lines | 76 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | import React, { Component } from "react" |
||
13 | render() { |
||
14 | const { |
||
15 | title, |
||
16 | icon = null, |
||
17 | body = null, |
||
18 | localFile, |
||
19 | link, |
||
20 | metadata = false, |
||
21 | tags = [], |
||
22 | created = null, |
||
23 | } = this.props |
||
24 | |||
25 | const image = ( |
||
26 | <Img |
||
27 | fluid={{ |
||
28 | ...localFile.childImageSharp.fluid, |
||
29 | aspectRatio: 3 / 2, |
||
30 | }} |
||
31 | alt={title} |
||
32 | /> |
||
33 | ) |
||
34 | |||
35 | const absoluteUrlRegex = /^https?:\/\/|^\/\//i |
||
36 | |||
37 | return ( |
||
38 | <article className={"cardItem"}> |
||
39 | {absoluteUrlRegex.test(link) || ( |
||
40 | <Link to={link}> |
||
41 | <header> |
||
42 | <figure>{image}</figure> |
||
43 | </header> |
||
44 | |||
45 | <main className={"cardItem__summary"}> |
||
46 | <div className={"cardItem__heading"}> |
||
47 | <h3>{icon && <Icon icon={icon}/>} {title}</h3> |
||
48 | </div> |
||
49 | |||
50 | {body && <div dangerouslySetInnerHTML={{ __html: body }}></div>} |
||
51 | </main> |
||
52 | </Link> |
||
53 | )} |
||
54 | |||
55 | {absoluteUrlRegex.test(link) && ( |
||
56 | <a href={link} target="_blank" rel="noopener noreferrer"> |
||
57 | <header> |
||
58 | <figure>{image}</figure> |
||
59 | </header> |
||
60 | |||
61 | <main className={"cardItem__summary"}> |
||
62 | <div className={"cardItem__heading"}> |
||
63 | <h3>{icon && <i className={`fa ${icon}`} aria-hidden={true}></i>} {title}</h3> |
||
64 | </div> |
||
65 | |||
66 | {body && <div dangerouslySetInnerHTML={{ __html: body }}></div>} |
||
67 | </main> |
||
68 | </a> |
||
69 | )} |
||
70 | |||
71 | {metadata && ( |
||
72 | <footer className={"cardItem__footer article__tags"}> |
||
73 | <span className={"datetime"}> |
||
74 | <i className={"fa fa-clock-o"} aria-hidden="true"></i> {created} |
||
75 | </span> |
||
76 | {tags.length > 0 && ( |
||
77 | <span className={"tag__wrapper"}> |
||
78 | <i className={"fa fa-tags"} aria-hidden="true"></i>{" "} |
||
79 | {tags.map(({ path, name }, i) => ( |
||
80 | <Link to={path.alias} key={i}> |
||
81 | <span className={"tag__label"}>#{name}</span> |
||
82 | </Link> |
||
83 | ))} |
||
84 | </span> |
||
85 | )} |
||
86 | </footer> |
||
87 | )} |
||
88 | </article> |
||
89 | ) |
||
214 |